#!/bin/bash
root_dir="/usr/local/edata"
if [ ! -d "$root_dir" ];then
  echo "$(date +"%Y-%m-%d %H:%M:%S") WARNING $root_dir undetected"
  mkdir -p $root_dir
  if [ $? -eq 0 ];then
    echo "$(date +"%Y-%m-%d %H:%M:%S") INFO creating $root_dir success"
  else
    echo "$(date +"%Y-%m-%d %H:%M:%S") ERROR creating $root_dir fail"
    exit 1
  fi
else
  echo "$(date +"%Y-%m-%d %H:%M:%S") INFO $root_dir detected"
fi


if [ ! -d "$root_dir/nebula" ];then
  echo "$(date +"%Y-%m-%d %H:%M:%S") INFO $root_dir/nebula undetected"
  tar -xvf nebula-graph-3.8.ubuntu2004.amd64.tar.gz
  mv nebula-graph-3.8.0.ubuntu2004.amd64 $root_dir/nebula
  
else
  echo "$(date +"%Y-%m-%d %H:%M:%S") WARNING $root_dir/nebula detected"
fi

if [[ -z "$NEBULA_HOME" ]];then
  echo "export NEBULA_HOME=$root_dir/nebula" >> ~/.bashrc
  echo 'export PATH=$NEBULA_HOME/bin:$NEBULA_HOME/scripts:$PATH' >> ~/.bashrc
  echo "export NEBULA_HOME=$root_dir/nebula" >> /etc/profile
  echo 'export PATH=$NEBULA_HOME/bin:$NEBULA_HOME/scripts:$PATH' >> /etc/profile
  source ~/.bashrc
  source /etc/profile
else
  echo "$(date +"%Y-%m-%d %H:%M:%S") INFO NEBULA_HOME is set"
fi

echo "$(date +"%Y-%m-%d %H:%M:%S") INFO installing JDK success"



